package com.bym.mall.config;

import com.bym.mall.interceptor.UserLoginInterceptor;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * springmvc的拦截器配置
 *
 * @author My
 * @date 2022/03/23
 */
@SpringBootConfiguration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截
        registry.addInterceptor(new UserLoginInterceptor())
                .addPathPatterns("/mall/user/**")
                .addPathPatterns("/mall/cart/**")
                .addPathPatterns("/mall/shipping/**")
                .addPathPatterns("/mall/order/**")
                .addPathPatterns("/mall/product/**")
                .addPathPatterns("/mall/category/**")
                //不拦截
                .excludePathPatterns("/mall/user/register")
                .excludePathPatterns("/mall/user/login")
                .excludePathPatterns("/mall/user/getCode")
                .excludePathPatterns("/mall/user/loginByPhoneAndCode")
                .order(1)
        ;
    }
}
